package com.example.travel.fragment;

import android.app.AlertDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import com.example.travel.Adapter.MyListViewAdapter;
import com.example.travel.R;

import java.util.ArrayList;

public class travel_list_fragment extends Fragment {
    static ArrayList<String> name2 = new ArrayList<>();
    static ArrayList<Integer>images2 =new ArrayList<>();
    static ArrayList<String> price2 =new ArrayList<>();
    static ArrayList<String> introduction2 = new ArrayList<>();


    @Override
    public View onCreateView( LayoutInflater inflater,  ViewGroup container,  Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.travel_listpro,container,false);

        final int[]images={R.drawable.twg, R.drawable.lhs, R.drawable.ls, R.drawable.cc, R.drawable.bmy};
        final String [] name ={"滕王阁","龙虎山","庐山","长城","兵马俑"};
        final String [] price={"A","A+","A","S+","S-"};
        final String [] introduction={"物华天宝，龙光射牛斗之墟；人杰地灵，徐孺下陈蕃之榻。",
                "瀑布斜飞，藤罗倒挂。虎啸时风生谷口，猿啼时版月坠山腰。",
                "不识庐山真面目，只缘身在此山中",
                "不到长城非好汉，是中华人民的骄傲，也是整个人类的骄傲",
                "神采奕奕，栩栩如生"};
        Button bt1=view.findViewById(R.id.bt1);
        Button bt2=view.findViewById(R.id.bt2);
        ListView listView = view.findViewById(R.id.listView);
        MyListViewAdapter myListViewAdapter = new MyListViewAdapter(getContext(),images,name,price,introduction);
        listView.setAdapter(myListViewAdapter);

        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {


                name2.add(name[i]);
                images2.add(images[i]);
                price2.add(price[i]);
                introduction2.add(introduction[i]);

                return true;
            }
        });
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AlertDialog.Builder dialog =new AlertDialog.Builder(getActivity());
                dialog.setIcon(R.drawable.ic_menu_largetiles);
                dialog.setTitle("Welcome to Easy travel");
                dialog.create();
                dialog.show();
            }
        });
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment search_travel_fragment =new search_travel_fragment();
                getFragmentManager().beginTransaction().replace(R.id.flconent,search_travel_fragment)
                        .commit();
            }
        });
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment travel_shopping_car_fragment =new travel_shopping_car_fragment();
                getFragmentManager().beginTransaction().replace(R.id.flconent,travel_shopping_car_fragment)
                        .commit();
            }
        });
        return view;
    }
    public View addImgView(int id) {
        ImageView iv=new ImageView(getContext());
        iv.setBackgroundResource(id);
        return iv;
    }
}
